package com.base.map;

import android.content.Context;

import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;

/**
 * Created by arvin on 2018/8/23.
 */

public class LocationUtil {
    private AMapLocationClient mLocationClient;

    public static final int LOCATION_SUCCESS=0;

    public LocationUtil(Context context) {
        this(context,true);
    }


    public LocationUtil(Context context, boolean needAddress) {
        mLocationClient = new AMapLocationClient(context);
        AMapLocationClientOption option = new AMapLocationClientOption();
        option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        option.setOnceLocation(true);
        option.setOnceLocationLatest(true);
        option.setHttpTimeOut(8000);
        option.setNeedAddress(needAddress);
        option.setLocationCacheEnable(true);
        mLocationClient.setLocationOption(option);
    }

    public void setListener(AMapLocationListener listener)
    {
        mLocationClient.setLocationListener(listener);
    }

    public void startLocation() {
        mLocationClient.startLocation();
    }

    public void unRegister(AMapLocationListener listener)
    {
        mLocationClient.unRegisterLocationListener(listener);
    }



    //只是停止定位，不销毁服务
    public void stopLocation() {
        mLocationClient.stopLocation();
    }


    //停止定位，并销毁服务
    public void destroyLocation() {
        mLocationClient.stopLocation();
        mLocationClient.onDestroy();

    }


}
